<style scoped>
span {
  font-size: 15px
}

.dialog-footer button:first-child {
  margin-right: 10px;
}

.el-menu-item is-active {
  color: #535bf2;
  background-color: #1a1a1a;
}


/**/
.el-button--text {
  margin-right: 15px;
}

.el-select {
  width: 300px;
}

.el-input {
  width: 300px;
}

.dialog-footer button:first-child {
  margin-right: 10px;
}


.el-button--text {
  margin-right: 15px;
}

.el-select {
  width: 300px;
}

.el-input {
  width: 300px;
}

.dialog-footer button:first-child {
  margin-right: 10px;
}
</style>

<template>
  <div>
    <el-dialog v-model="centerDialogVisible" title="确认" width="30%" center>
      <template #default>您将删除条目:{{ fromDelete.name }}</template>
      <template #footer>
      <span class="dialog-footer">
        <el-button @click="centerDialogVisible = false">取消</el-button>
        <el-button type="danger" :disabled="BtnConfirmAble" @click="deleteRow">确定</el-button>
      </span>
      </template>
    </el-dialog>

    <!--修改弹窗-->
    <el-dialog v-model="editDialogVisible" :title=formEdit.PopupType width="40%" center>
      <el-form :model="formEdit">
        <el-form-item label="图书类别名称" :label-width="formLabelWidth"
                      :rules="{required:!formEdit.typeName,message:'此项必填!'}">
          <el-input :size="inputSize" v-model="formEdit.typeName" autocomplete="off"/>
        </el-form-item>
      </el-form>
      <template #footer>
      <span class="dialog-footer">
        <el-button @click="Cancel">取消</el-button>
        <el-button type="primary" :disabled="BtnConfirmAble" @click="ConfirmEdit(formEdit)">确认</el-button>
      </span>
      </template>
    </el-dialog>
    <!--table显示-->
<!--    <div style="margin-bottom: 10px;width: 100%">-->
<!--      <el-input-->
<!--          v-model.trim="search.name"-->
<!--          class="w-50 m-2"-->
<!--          size="default"-->
<!--          @keyup.enter="getTableData"-->
<!--          placeholder="名称">-->
<!--      </el-input>-->
<!--      <el-button style="margin-left: 60px;" size="default" type="primary" @click="getTableData">-->
<!--        <el-icon>-->
<!--          <Search/>-->
<!--        </el-icon>-->
<!--      </el-button>-->
<!--    </div>-->


    <el-scrollbar>
      <el-table v-loading="loading" :header-cell-style="{background:'#eef1f6',color:'#606266'}" border
                :row-style="{height: '54.7px'}"
                style="font-size: 15px" stripe :data="tableData">
        <el-table-column label="图片" width="auto">
          <template #default="scopeEdit">
            <div class="demo-image">
              <div class="block">
                <el-image style="width: 100px; height: 100px" :src="'/api/file/img?name='+scopeEdit.row.img"
                          fit="cover"/>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="名称" width="auto"/>
        <el-table-column prop="userInName" label="租入" width="auto"/>
        <el-table-column prop="userOutName" label="租出" width="auto"/>

        <el-table-column label="价格" width="auto">
          <template #default="scope">
            <label> {{ scope.row.price }}/{{ getUnitText(scope.row.unit) }}</label>
          </template>
        </el-table-column>
        <el-table-column label="状态" width="auto">
          <template #default="scope">
            <label> {{ getAgreeText(scope.row.status) }} </label>
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="备注" width="auto"/>
<!--        <el-table-column prop="createTime" label="创建时间" width="auto"/>-->
<!--        <el-table-column fixed="right" label="操作">-->
<!--          <template #default="scopeEdit">-->
<!--            <el-button-->
<!--                v-if="scopeEdit.row.status===0"-->
<!--                link-->
<!--                type="danger"-->
<!--                size="small"-->
<!--                @click.prevent="deleteLog(scopeEdit.row.id,-->
<!--                scopeEdit.row.name)">-->
<!--              <el-icon>-->
<!--                <Delete/>-->
<!--              </el-icon>-->
<!--              <span>删除</span>-->
<!--            </el-button>-->
<!--          </template>-->
<!--        </el-table-column>-->

      </el-table>
    </el-scrollbar>

  </div>
</template>

<script lang="ts" setup>

import {onMounted, reactive, ref, watch} from "vue";
import {Delete, Edit, Operation, Search} from '@element-plus/icons-vue'

import {

  searchAllApi
} from "@/api/market";
import {ElMessage} from "element-plus";
import {ElLoading} from "element-plus/es";
import {getAgreeText, getLendText, getUnitText} from "@/utils/auth";

const centerDialogVisible = ref(false)

//搜索功能
const inputSearch = ref([])


//数据初始化
onMounted(() => {
  getTableData()
})

const rolesList = ref<any[]>([])
//分页
const page = reactive({
  current: 1,
  limit: 10,
  total: 0,
})


//分页操作
function handleCurrentChange(e: any) {
  getTableData()
}

const tableData = ref([])
const loading = ref(true)
const search = reactive({
  author: "",
  name: "",
  tid: ""
})

function getTableData() {
  searchAllApi({name:search.name}).then((response: any) => {
    if (response.code === 200) {
      tableData.value = response.data
      page.total = response.data.total
    } else {
      ElMessage.warning(response.message)
    }
    loading.value = false
  }).catch(function (res:any) {
    loading.value = false
    ElMessage.error("页面加载失败")
  })
}


//添加修改数据初始化
const BtnConfirmAble = ref(true)


const formEdit = reactive({
  tid: "",
  typeName: "",
  PopupType: ""
})


//弹窗展示编辑表格
function editRow(row: any) {
  formEdit.tid = row.tid
  formEdit.typeName = row.typeName
  formEdit.PopupType = PopupType.value[1]
  editDialogVisible.value = true;
}

//修改字段检测
watch(() => ({...formEdit}), (count, prevCount) => {
  if (count.typeName == '') {
    BtnConfirmAble.value = true
  } else {
    BtnConfirmAble.value = false
  }
})



function Cancel() {
  editDialogVisible.value = false;
}


//添加系统用户
const editDialogVisible = ref(false)

const PopupType = ref(['添加', '编辑'])

function addInitialize() {
  formEdit.tid = "";
  formEdit.typeName = "";
  formEdit.PopupType = PopupType.value[0]
  editDialogVisible.value = true;
}

const fromDelete = reactive({
  id: -1,
  name: ''
})

//删除
function deleteLog(id: any, name: any) {
  fromDelete.id = id
  fromDelete.name = name
  centerDialogVisible.value = true;
  BtnConfirmAble.value = false;
}

const formLabelWidth = '140px'
const inputSize = 'default'

</script>
